<template>
  <div>
       <el-form :inline="true" :model="enterprise" class="demo-form-inline">
  <el-form-item label="状态">
    <el-select v-model="enterprise.state" placeholder="请选择状态">
      <el-option label="待审核" value="2"></el-option>
      <el-option label="复核" value="3"></el-option>
    </el-select>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="condition()">查询</el-button>
    
    <el-button icon="el-icon-delete" type="primary" @click="enterprise={}">清空</el-button>
  </el-form-item>
</el-form>
  <!-- 表格   -->
    <el-table
    :data="page.records"
    border
    style="width: 90%">
        <el-table-column
        prop="id"
        label="企业ID"
        width="80">
        </el-table-column>
        <el-table-column
        prop="name"
        label="企业名"
        width="180">
        </el-table-column>
        <el-table-column
        prop="enPhone"
        label="企业电话"
         width="130">
        </el-table-column>
        <el-table-column
        prop="registrationNo"
        label="工商注册号"
         width="190">
        </el-table-column>
        <el-table-column
        prop="userId"
        label="用户"
         width="120">
        <template slot-scope="scope">
            {{scope.row.tbUser.username}}
        </template>
        </el-table-column>
        <el-table-column
        prop="natureId"
        label="性质"
         width="130">
        <template slot-scope="scope">
            {{scope.row.tbEnNature.name}}
        </template>
        </el-table-column>
        <el-table-column
        prop="createTime"
        label="创建时间"
         width="140">
        </el-table-column>
        <el-table-column
        prop=""
        label="状态"
         width="120">
        <template slot-scope="scope">
            <el-tag v-if="scope.row.state==0" type="success" >封禁</el-tag>
            <el-tag v-if="scope.row.state==1" type="error" >正常</el-tag>
            <el-tag v-if="scope.row.state==2" type="danger">待审核</el-tag>
            <el-tag v-if="scope.row.state==3" type="danger">审核不通过</el-tag>
        </template>
        </el-table-column>
         <el-table-column label="操作">
      <template slot-scope="scope">
          <el-button
          size="mini"
          type="success"
          v-if="scope.row.state==2"
          @click="findById(scope.row.id)">审核</el-button>
         <el-button
           size="mini"
           type="danger"
           v-if="scope.row.state==3"
           @click="findById(scope.row.id)">重审</el-button>
      </template>
    </el-table-column>
  </el-table>
  <!-- 分页 -->
  <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page.current"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="page.size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="page.total">
    </el-pagination>


<el-dialog
  title="提示"
  :visible.sync="dialogVisible"
  width="35%"
  :before-close="handleClose">
<el-form ref="form" :model="tbEnterprise" label-width="120px">
  <el-form-item label="企业名称">
    <el-input disabled v-model="tbEnterprise.name"></el-input>
  </el-form-item>
  <el-form-item label="工商注册号">
    <el-input disabled v-model="tbEnterprise.registrationNo"></el-input>
  </el-form-item>
  <el-form-item label="企业电话">
    <el-input disabled v-model="tbEnterprise.enPhone"></el-input>
  </el-form-item>
  <el-form-item label="负责人">
    <el-input disabled v-model="tbEnterprise.chargePerson"></el-input>
  </el-form-item>
  <el-form-item label="负责人电话">
    <el-input disabled v-model="tbEnterprise.chargePhone"></el-input>
  </el-form-item>
  <el-form-item label="地址">
    <el-input disabled v-model="tbEnterprise.address"></el-input>
  </el-form-item>
  <el-form-item label="性质">
    <el-input disabled v-model="tbEnterprise.tbEnNature.name"></el-input>
  </el-form-item>
   <el-form-item label="属于用户">
    <el-input disabled v-model="tbEnterprise.tbUser.username"></el-input>
  </el-form-item>
</el-form>
  <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="success" @click="examine(tbEnterprise.id)">通 过</el-button>
    <el-button type="primary" @click="failedExamine(tbEnterprise.id)">不通过</el-button>
  </span>
</el-dialog>

  </div>
</template>

<script>
import {findEnterpriseByState,findById,failedExamine ,examine} from "@/api/enterprise"
export default {
    data() {
        return {
            enterprise:{
                
            },
            page:{
                current:1,
                size:10,
                total:0
            },
            tbEnterprise:{
                tbEnNature:{},
                tbUser:{}
            },
            dialogVisible:false
        }
    },
    methods: {
         async condition(){
            this.enterprise.size = this.page.size;
            this.enterprise.current = this.page.current;
            let {data} = await findEnterpriseByState(this.enterprise)
            this.page =data
        },
        handleSizeChange(val) {
        this.page.size  = val
        this.condition()
        },
        handleCurrentChange(val) {
            this.page.current = val
            this.condition()
        },
        async failedExamine(id){
            let {message} = await failedExamine(id);
            this.$message.warning(message)
             this.condition()
              this.dialogVisible = false
        },
        async examine(id){
            let {message} = await examine(id);
            this.$message.success(message)
             this.condition()
             this.dialogVisible = false
        },
        async findById(id){
            console.log(id)
             let {data} = await findById(id);
             this.tbEnterprise = data
             this.dialogVisible = true
        },
        handleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            done();
          })
          .catch(_ => {});
        }
        
    },
    mounted() {
        this.condition()
    },

}
</script>

<style>

</style>